﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace Vision.Common
{
    public class CDrawObj
    {
        protected bool m_visible = true;
        /// <summary>
        /// 是否显示
        /// </summary>
        public bool Visible { get => m_visible; set => m_visible=value; }

        protected TrackerState m_state;
        [JsonIgnore]
        public virtual TrackerState State { get=> m_state; set=>m_state = value; } //属性
        [JsonIgnore]
        public Object Tag { get; set; }
        /// <summary>
        /// 绘制
        /// </summary>
        /// <param name="g">GDI</param>
        /// <param name="scale">缩放比例</param>
        public virtual void Draw(Graphics g, float scale = 1) { }

        public virtual TrackerInfo GetTrack(PointF pt,float scale)
        {
            return new TrackerInfo() { pos = TrackerPos.tOut, para =0};
        }
        public virtual void Move(float dx,float dy) { }

        protected bool IntersectsWith(float x, float y, float xMin, float xMax, float yMin, float yMax)
        {
            return x >= xMin && x <= xMax && y >= yMin && y <= yMax;
        }
        public CDrawObj Copy()
        {
            CDrawObj obj = new CDrawObj();
            CopyTo(obj);
            return obj;
        }

        public void CopyTo(CDrawObj node)
        {
            node.m_visible = m_visible;
            node.State = State;
        }
        public virtual void ReadSelfAttrbutes(XmlReader reader)
        {
            Visible = Convert.ToBoolean(reader.GetAttribute("Visible"));
        }

        public virtual void WriteSelfAttrbutes(XmlWriter writer)
        {
            writer.WriteAttributeString("Visible", Visible.ToString());
        }
    }

    public struct TrackerInfo
    {
        public TrackerPos pos;
        public int para;
    }

    public enum TrackerState
    {
        normal,     //常规
        selected,   //选中
        active      //激活
    }

    public enum TrackerPos
    {
        tIn,
        tOut,
        tBorderOne,
        tBorderTwo
    }

}
